<? require_once('classes/Craigslist.php'); 


$craig = new Craigslist();

$craig_r = $craig->fetch();

$d = $craig_r->ads;

/*
echo '<textarea rows=100 cols=100>';
print_r($d);
echo '</textarea>';
*/


/*
foreach($d as $c){

print_r($c);

}
exit;
*/

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Maps JavaScript API Example</title>
    <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAREkopdB2DthaLKWLXUcWgxQoU8h1rNpuPlavOloCdSisrcvaLRTN2drNPlHMzM4OcpCreBqE1PmA8g"
      type="text/javascript"></script>
    <script type="text/javascript">

    //<![CDATA[

   var geocoder;
   var map;
	 var counter;	
	  var address=new Array();
	  var title=new Array();
	  var body=new Array();
   	
   	<? 
   	$i=0;
   	
   	foreach($d as $c){ 
   	
   	
   	
   	$add = str_replace("%3A%31%32%","",$c->details->location);
   	$add = str_replace("%","",$add);
   	$add = str_replace("+"," ",$add);
   	
   	
   	?>
   	
   	
   	
   	address[<?= $i ;?>] = "<?=htmlentities($add);?>";
    title[<?= $i ;?>] = "<?= htmlentities($c->title);?>";
		body[<?= $i ;?>] = "<?= htmlentities($c->details->body);?>";
	 <? 
	 $i++;
	 } 
	 ?>	
		
   // On page load, call this function

   function load()
   {
      // Create new map object
      map = new GMap2(document.getElementById("map"));
			map.setUIToDefault();
			map.setCenter(new GLatLng(40.80601358609009, -73.9463996887207), 13);
      var myCounter = new Counter();

      // Create new geocoding object
      geocoder = new GClientGeocoder();

      // Retrieve location information, pass it to addToMap()
    
   
   
   
    for (x in address) {
    
      geocoder.getLocations(address[x], addToMap);
      
    }
   }

   // This function adds the point to the map
iki = 0;
   function addToMap(response)
   {
      // Retrieve the object
      place = response.Placemark[0];

      // Retrieve the latitude and longitude
      point = new GLatLng(place.Point.coordinates[1],
                          place.Point.coordinates[0]);

      // Center the map on this point
     map.setCenter(point, 13);


      // Create a marker
      marker = new GMarker(point);

      // Add the marker to map
      map.addOverlay(marker);
      
      console.log("@"+myCounter.getValue);
      
      GEvent.addListener(marker, "click", function() {
							  //map.closeInfoWindow();
							  
							 this.openInfoWindowHtml(title[myCounter.getValue] + "<br>" + place.address);
	
			});
			myCounter.increment;
      // Add address information to marker
      //marker.openInfoWindowHtml(place.address);
   }
   
   function Counter() {
  	this.counter = 0;
		}
		
		Counter.prototype.getValue = function(){ return this.counter;}

   Counter.prototype.increment = function() {
  this.counter++;
  }
   

    //]]>
    </script>
  </head>
  <body onload="load()" onunload="GUnload()">
  <form action="" method="get" onsubmit="ckCAbb();">

		<table width="100%" cellpadding="2" style="white-space: nowrap; background:#eee; border:1px solid gray;" summary="">
		<tr>
			<td align="right" width="1">search for:</td>
			<td width="30%"><input id="query" name="query" size="30" value=""> in:
				<select id="cAbb" name="catAbbreviation">

<option value="ccc">all community<option value="eee">all event<option value="sss">all for sale / wanted<option value="ggg">all gigs<option value="hhh">all housing<option disabled value="">--<option value="aap" selected>   all apartments
<option value="hsw">   all housing wanted
<option value="nfa">   all no fee apts
<option value="fee">   apts broker fee
<option value="nfb">   apts broker no fee
<option value="abo">   apts by owner

<option value="aiv">   apts registration fee
<option value="hou">   apts wanted
<option value="swp">   housing swap
<option value="off">   office &amp; commercial
<option value="prk">   parking &amp; storage
<option value="rea">   real estate - all
<option value="reb">   real estate - by broker

<option value="reo">   real estate - by owner
<option value="rew">   real estate wanted
<option value="roo">   rooms &amp; shares
<option value="sha">   rooms wanted
<option value="sbw">   sublet/temp wanted
<option value="sub">   sublets &amp; temporary
<option value="vac">   vacation rentals

<option disabled value="">--<option value="jjj">all jobs<option value="ppp">all personals<option value="res">all resume<option value="bbb">all services offered</select>
				<input type="submit" value="Search">
			</td><td>
				<label><input type="checkbox" name="srchType" value="T"
					title="check this box to search only posting titles"> only search titles</label>
			</td>
		</tr>

	
		<tr>
			<td align="right" width="1">rent:</td>
			<td><input name="minAsk" size="6" value="1000">&nbsp;<input name="maxAsk" size="6" value="1400">&nbsp;&nbsp;&nbsp;<select name="bedrooms">
<option value="">0+ BR
<option value="1" selected>1 BR
<option value="2">2 BR
<option value="3">3 BR
<option value="4">4 BR
<option value="5">5 BR
<option value="6">6 BR
<option value="7">7 BR
<option value="8">8 BR
</select>

<select name="neighborhood"><option value="">all neighborhoods
<option value="120">Battery Park
<option value="134">Chelsea
<option value="160">Chinatown / Lit Italy
<option value="121">Downtown
<option value="159">East Harlem
<option value="129">East Village
<option value="122">Financial District
<option value="133">Flatiron
<option value="132">Gramercy
<option value="127">Greenwich Village
<option value="141" selected>Harlem / Morningside
<option value="140">Inwood / Wash Hts
<option value="126">Lower East Side
<option value="135">Midtown
<option value="136">Midtown East
<option value="137">Midtown West

<option value="131">Murray Hill
<option value="125">Nolita / Bowery
<option value="124">SoHo
<option value="123">TriBeCa
<option value="130">Union Square
<option value="139">Upper East Side
<option value="138">Upper West Side
<option value="128">West Village
</select>
&nbsp;&nbsp;&nbsp;
				<label><input type="checkbox" name="addTwo"  value="purrr">cats</label>
				<label><input type="checkbox" name="addThree" value="wooof">dogs</label>
</td>

			<td align="left"><label><input type="checkbox" name="hasPic" value="1"> has image</label></td>
		</tr></table>
</form>
    <div id="map" style="width: 100%; height: 600px"></div>
  </body>
</html>
